﻿define(['admin/app', "service/admin/sendContentService"], function (app) {
    "use strict";

    app.controller('sendContentController', function ($scope, $stateParams, $location, utils, sendContentService) {
        $scope.psdisabled = false;
        var methods = {
            search: function () {
                sendContentService.get({ type: $stateParams.type }).success(function (response) { $scope.list = response.data; });
            },
            save: function () {
                var data = { type: $stateParams.type };
                var j = 0;
                for (var i = 0; i < $scope.list.length; i++) {
                    if ($scope.list[i].check)
                        data['codes[' + (j++) + ']'] = $scope.list[i].code;
                }
                sendContentService.put(data).success(function (response) {
                    utils.notify(response.result_msg, response.result_code == 1000 ? "success" : "warning");
                    if (response.result_code == 1000)
                        methods.search();
                    else
                        $scope.psdisabled = false;
                }).error(function () { $scope.psdisabled = false; });
            }
        }

        switch ($stateParams.type) {
            case "1":
                $scope.breadcrumb = "APP消息";
                break;
            case "2":
                $scope.breadcrumb = "短信";
                break;
            case "3":
                $scope.breadcrumb = "微信";
                break;
        }

        methods.search();

        angular.extend($scope, methods);
    });
});
